/*
 * randomtestcard.c
 *
 *  Created on: Jul 23, 2014
 *      Author: Wing Yee Leung
 *
 * Note: This is a random unit test for the great_hall card
 * 		 The card is of type Action - Victory.
 *		 Effect is +1 card, +1 action, 1 Vp
 *		 Cost is 3 Coins.
 *
 *		
 */
#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <time.h>

#define TESTCARD "great_hall"
#define NUMTESTS 15000


int checkGreat_hall(struct gameState *state, int handPos, int thisPlayer) {

	int choice1, choice2, choice3, pass = 1;
	struct gameState testG;
	
	//copy original struct to a new struct
	memcpy (&testG, state, sizeof(struct gameState));	
 
	//doesn't really matter here to be honest becuase choices don't get used in great hall method
	choice1 = floor(Random() * 256);
	choice2 = floor(Random() * 256);
	choice3 = floor(Random() * 256);
	
	//call method on test strcut
	cardEffect(great_hall, choice1, choice2, choice3, &testG, handPos, 0);	

	// Check that result is correct
	printf("\tHand count = %d, expected = %d\n", testG.handCount[thisPlayer], state->handCount[thisPlayer]); 
	printf("\tNumber of actions %d, expected = %d\n", testG.numActions, state->numActions + 1);
	
	//gains a card, but discards a card
	if(testG.handCount[thisPlayer] == state->handCount[thisPlayer]) {
		printf("\t\tPASS: hand count accurate \n");
	}	
	else {
		printf("\t\tFAIL: hand count accurate");
		pass = 0;
	}
		
	//gains an action
	if(testG.numActions == state->numActions + 1) {
		printf("\t\tPASS: number of actions accurate.  \n");
		
	}
	else {
		printf("\t\tFAIL: hand count accurate. \n");
		printf("\t\tPlayer number %d \n", thisPlayer);
		pass = 0;
	}
	
	return pass;
}


int main() {

	int j, deckCt, discardCt, handCt, handPos, numPlayers, pass = 1;
	int thisPlayer;
 	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
		sea_hag, tribute, smithy};
	srand(time(NULL));
	
	printf("----------------- Testing Card: %s ----------------\n", TESTCARD);

	for(j = 0; j < NUMTESTS; j++) {

		printf("Test %d:\n", j);
	
		SelectStream(j % 255);


		struct gameState G;
		memset(&G, 0, sizeof(struct gameState));
		
		//randomize number of players
		numPlayers = 2 + (int)floor(Random() * (MAX_PLAYERS - 2));

		//initialize Game
		initializeGame(numPlayers, k, rand(), &G);

		
		G.numPlayers = numPlayers;
		
		//set current player
		thisPlayer = (int)floor(Random() * numPlayers);

		//randomize card counts

		handCt = (int)floor(Random() * MAX_HAND);
		deckCt = (int)floor(Random() * (MAX_DECK - handCt));
		discardCt = (int)floor(Random() * (MAX_DECK - deckCt));
		
		//set card counts
		G.handCount[thisPlayer] = handCt;
		G.deckCount[thisPlayer] = deckCt;
		G.discardCount[thisPlayer] = discardCt;
		
		G.playedCardCount = (int)floor(Random() * MAX_DECK);
						
		G.whoseTurn = thisPlayer;
		
		//randomzie and set number of actions 
		G.numActions = (int)floor(Random() * 10);
		
		//randomize and set handPos within range of handCount
		handPos = floor(Random() * (G.handCount[thisPlayer]));	

		pass = checkGreat_hall(&G, handPos, thisPlayer);

	}
	
	if(pass == 1)
		printf("\n >>>>> SUCCESS: Testing complete for %s <<<<<\n\n", TESTCARD);
	else
		printf("\n >>>>> FAIL: Not all tests passed for %s <<<<<\n\n", TESTCARD);
	
	return 0;
}





